<?
$action = new Action();
class Action
{
	function Action()
	{
		global $gAct,$gOp,$gSmarty;
		$gSmarty->assign("act",$gAct);
		switch($gOp)
		{
			case "saveFile":
			    $this->saveFile();
				break;
			case "saveFileImg":
			    $this->saveFileImg();
				break;
			case "detail":
			    $this->detail();
				break;
			case "ajaxType":
			    $this->ajaxType();
				break;
			case "ajaxDel":
			    $this->ajaxDel();
				break;
			case "saveInfo":
			     $this->saveInfo();
			    break;
			case "ajaxLstDir": 
				$this->ajaxLstDir();
			    break;
			case "ajaxSaveDir":
			    $this->ajaxSaveDir();
			    break;
			case "ajaxDelDir":
			    $this->ajaxDelDir();
			    break;
			case "ajaxDirFile":
			    $this->ajaxDirFile();
			    break;
			case "ajaxRemoveFile":
			    $this->ajaxRemoveFile();
				break;
			case "ajaxSaveFileType":
			    $this->ajaxSaveFileType();
				break;
			case "removeFileDirType":
			    $this->removeFileDirType();
				break;
			case "removeAllFileDirType":
			    $this->removeAllFileDirType();
				break;
			case "doAddApplyList":
			    $this->doAddApplyList();
			    break;
			case "ajaxSaveFile":
			    $this->ajaxSaveFile();
				break;
			case "getLstFile":
			    $this->getLstFile();
			    break;
			case "getTips":
			    $this->getTips();
				break;
			case "upload":
			    $this->upload();
				break;
			case "getSubjectInfo":
			    $this->getSubjectInfo();
			    break;
			default:
				$this->index();
				break;
		}
	}
	function getSubjectInfo()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime,$GJson,$_SESSION,$gFileType;
		if($INCOME['id'])
		{
	
			$dqf = $DB->db_query_first("select path,mark,fileTypeId,pic,ext from res_file_subject where id=".$INCOME['id']);
			if($dqf['fileTypeId']!=39)
			{
				if($dqf['pic'])
				{
					$dqf['path'] = str_replace(".","s.",$dqf['pic']);
				}
				else
				{
					$dqf['path'] = $gFileType[$dqf['ext']]['p'];
				}
			}
			echo $GJson->encode(array("name"=>$dqf['mark'],"path"=>$dqf['path']));
		}
		else
		{
			echo $GJson->encode(array("name"=>null,"path"=>null));
		}
	}
	function upload()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime,$GJson,$_SESSION;
 
		$gSmarty->display("filegroup/".__FUNCTION__.".tpl");
	}
	function getTips()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime,$GJson,$_SESSION;
		if($_SESSION['adminUser']['roleId']!=1 && $_SESSION['adminUser']['roleId']!=4)
		{
			$con = "uid=".$_SESSION['adminUser']['id']." and";
		}
		$DB->db_query("select zhuanTi from res_file where $con isGroupTop = 0 and isDel=0 group by zhuanTi order by zhuanTi");
		$ids = array();
		if($DB->db_fetch_num()>0)
		{
			$ids = array();
			while($r=$DB->db_fetch_row())
			{
				if($r['zhuanTi'])
				{
				    $ids[] = $r['zhuanTi'];
				}
			}
		}
		echo $GJson->encode($ids);
	}
	function ajaxSaveFile()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime,$GJson,$_SESSION;
		$f  = $INCOME['fileData'];
		if($f || $INCOME['group'])
		{
			if($_SESSION['adminUser']['roleId']!=1 && $_SESSION['adminUser']['roleId']!=4)
			{
				$userCon = "and uid=".$_SESSION['adminUser']['id']."";
			}
			if($INCOME['id'] && $INCOME['id']!=-1)
			{
				$row = $DB->db_query_first("select * from res_file_subject where id!=".$INCOME['id']." and zhuanTi='".$INCOME['group']."' $userCon and isDel=0");
				if($row)
				{
					echo $GJson->encode(array("st"=>"err","msg"=>"专题已经存在"));exit;
				}
				$row = $DB->db_query_first("select * from res_file_subject where id=".$INCOME['id']." and isDel=0 $userCon");
				if(empty($row))
				{
					echo $GJson->encode(array("st"=>"err","msg"=>"专题不存在"));exit;
				}
				//echo $INCOME['id'];
				if($f)
				{
					$f = unserialize(base64_decode($f));
				}
				if(is_array($f))
				{
					unset($f['addTime']);
				}
				$f['edtTime']=$gCurTime;
				$row = $DB->db_query_first("select * from res_file_subject where zhuanTi='".$INCOME['group']."' and isDel=0 and isGroupTop=0 $userCon");
				//$f['carIds'] = $row['carIds'];
				//$f['typeIds'] = $row['typeIds'];
				//$f['carNames'] = $row['carNames'];
				//$f['typeNames'] = $row['typeNames'];
				$f['mark'] = $INCOME['group'];
				$f['zhuanTi'] = $INCOME['group'];
				$DB->db_form_update("res_file_subject",$f,"id=".$INCOME['id'],false);
				//if($INCOME['oldGroup'])
				//{
					//unset($f['mark']);
					//$DB->db_form_update("res_file",$f,"sid='".$INCOME['id']."' $userCon ");
				//}
				$data = array("st"=>"ok","msg"=>"成功");
			}
			else
			{
				if($f && $INCOME['group'])
				{
				}
				else
				{
					echo $GJson->encode(array("st"=>"err","msg"=>"失败"));exit;
				}
				$row = $DB->db_query_first("select * from res_file where zhuanTi='".$INCOME['group']."' and isDel=0 and isGroupTop>0 $userCon");
				if($row)
				{
					echo $GJson->encode(array("st"=>"err","msg"=>"专题已经存在"));exit;
				}
				$row = $DB->db_query_first("select * from res_file_subject where zhuanTi='".$INCOME['group']."' and isDel=0 $userCon");
				if($row)
				{
					echo $GJson->encode(array("st"=>"err","msg"=>"专题已经存在"));exit;
				}
				$row = $DB->db_query_first("select count(*) as num from res_file where zhuanTi='".$INCOME['group']."' and isDel=0 and isGroupTop=0 $userCon");
				$f = unserialize(base64_decode($f));
				$f['zhuanTi'] = $INCOME['group'];
				$f['mark'] = $INCOME['group'];
				if($row && $row['num']>0)
				{
					
					$f['isGroupTop'] = $row['num'];
					$row = $DB->db_query_first("select * from res_file where zhuanTi='".$INCOME['group']."' and isDel=0 and isGroupTop=0 $userCon");
					$f['carIds'] = $row['carIds'];
					$f['typeIds'] = $row['typeIds'];
					$f['carNames'] = $row['carNames'];
					$f['typeNames'] = $row['typeNames'];
 					$f['isPost'] = 3;
					$DB->db_form_insert("res_file",$f);
					$DB->db_form_insert("res_file_subject",$f,false);
					$data = array("st"=>"ok","msg"=>"成功");
				}
				else
				{
					//$data = array("st"=>"err","msg"=>"找不到属于该主题的文件");
					$f['isPost'] = 3;
					$f['addTime'] = $gCurTime;
					$DB->db_form_insert("res_file_subject",$f,false);
					$data = array("st"=>"ok","msg"=>"成功");
				}
			}
			
		}
		else
		{
			$data = array("st"=>"err","msg"=>"失败");
		}
		echo $GJson->encode($data);
	}
	function doAddApplyList()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime,$GJson;
		if($INCOME['id'])
		{
			
		}
		else if($INCOME['dirId'])
	    {
			$DB->db_query("select id from res_file where dirIds like '%,".$INCOME['dirId'].",%' and isPost=3 and isDel=0");
			if($DB->db_fetch_num()>0)
			{
				$ids = array();
				while($r=$DB->db_fetch_row())
				{
					$ids[] = $r['id'];
				}
				$INCOME['id'] = implode(",",$ids);
			}
	    }
 
	    if(strlen($INCOME['id'])>0)
	    {
	    	$DB->db_query("update res_file set isPost=4 where sid in(".$INCOME['id'].") and isPost=3");
			$DB->db_query("update res_file_subject set isPost=4 where id in(".$INCOME['id'].") and isPost=3");
			
	    }
	    $data = array("st"=>"ok","msg"=>"成功","id"=>$ids[0]);
	    
 		echo $GJson->encode($data);
	}
	function removeAllFileDirType()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		if($INCOME['id']=="0" && $INCOME['pdid']>0)
		{
			$DB->db_query("select id from res_file where dirIds like '%,".$INCOME['pdid'].",%' and isPost=0");
			if($DB->db_fetch_num()>0)
			{
				$ids = array();
				while($r=$DB->db_fetch_row())
				{
					$ids[] = $r['id'];
				}
				$INCOME['id'] = implode(",",$ids);
			}
		}
		if($INCOME['id'])
		{
			$DB->db_query("update res_file set typeIds='',typeNames='',carIds='',carNames='' where id in(".$INCOME['id'].")");
		}
		$ids = explode(",",$INCOME['id']);
		$data = array("st"=>"ok","msg"=>"成功","id"=>$ids[0]);
 		echo $GJson->encode($data);
	}
	function removeFileDirType()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		$r = $DB->db_query_first("select * from res_file where id=".$INCOME['id']);
		if($INCOME['type']=="1")
		{
			$t = explode(",",$r['typeIds']);
			$tn = explode(",",$r['typeNames']);
			unset($t[$INCOME['tid']]);
			unset($tn[$INCOME['tid']]);
			$DB->db_query("update res_file set typeIds=',".implode(",",$t).",',typeNames=',".implode(",",$tn).",' where id=".$INCOME['id']);
		}
		if($INCOME['type']=="2")
		{
			$c = explode(",",$r['carIds']);
			$cn = explode(",",$r['carNames']);
			unset($c[$INCOME['tid']]);
			unset($cn[$INCOME['tid']]);
			$DB->db_query("update res_file set carIds=',".implode(",",$c).",',carNames=',".implode(",",$cn).",' where id=".$INCOME['id']);
		}
		$data = array("st"=>"ok","msg"=>"成功");
 		echo $GJson->encode($data);
	}
	function ajaxSaveFileType()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		if($INCOME['id']=="0" && $INCOME['pdid']>0)
		{
			$DB->db_query("select id from res_file where dirIds like '%,".$INCOME['pdid'].",%' and isPost=0");
			if($DB->db_fetch_num()>0)
			{
				$ids = array();
				while($r=$DB->db_fetch_row())
				{
					$ids[] = $r['id'];
				}
				$INCOME['id'] = implode(",",$ids);
			}
		}
		if(strpos($INCOME['id'],",")===false)
		{
			$r = $DB->db_query_first("select * from res_file where id=".$INCOME['id']);
			$c = explode(",",$r['carIds']);
			$t = explode(",",$r['typeIds']);
 			$cn = explode(",",$r['carNames']);
			$tn = explode(",",$r['typeNames']);
			if($r['brandId'] && $r['carId'])
			{
				if(!in_array($r['brandId'] .":". $r['carId'],$c))
				{
					$c[] = $r['brandId'] .":". $r['carId'];
					$cn[] = $r['brandName'] .":". $r['carName'];
				}
			}
			if($r['typeId'] && $r['styleId'])
			{
				if(!in_array($r['typeId'] .":". $r['styleId'],$t))
				{
					$t[] = $r['typeId'] .":". $r['styleId'];
					$tn[] = $r['typeName'] .":". $r['styleName'];
				}
			}
		}
		else
		{
			$fids = explode(",",$INCOME['id']);
			$r = $DB->db_query_first("select * from res_file where id=".$fids[0]);
			$c = explode(",",$r['carIds']);
			$t = explode(",",$r['typeIds']);
 			$cn = explode(",",$r['carNames']);
			$tn = explode(",",$r['typeNames']);
			if($r['brandId'] && $r['carId'])
			{
				if(!in_array($r['brandId'] .":". $r['carId'],$c))
				{
					$c[] = $r['brandId'] .":". $r['carId'];
					$cn[] = $r['brandName'] .":". $r['carName'];
				}
			}
			if($r['typeId'] && $r['styleId'])
			{
				if(!in_array($r['typeId'] .":". $r['styleId'],$t))
				{
					$t[] = $r['typeId'] .":". $r['styleId'];
					$tn[] = $r['typeName'] .":". $r['styleName'];
				}
			}
		}
		if($INCOME['dbbrandId'] || $INCOME['dbcarId'])
		{
			if(!in_array($INCOME['dbbrandId'] .":". $INCOME['dbcarId'],$c))
			{
				$c[] = $INCOME['dbbrandId'] .":". $INCOME['dbcarId'];
				$cn[] = $INCOME['dbbrandName'] .":". $INCOME['dbcarName'];
			}
		}
		if($INCOME['dbtypeId']|| $INCOME['dbstyleId'])
		{
			if(!in_array($INCOME['dbtypeId'] .":". $INCOME['dbstyleId'],$t))
			{
				$t[] = $INCOME['dbtypeId'] .":". $INCOME['dbstyleId'];
				$tn[] = $INCOME['dbtypeName'] .":". $INCOME['dbstyleName'];
			}
		}
        $c = array_filter($c);
 		$cn = array_filter($cn);
 		$t = array_filter($t);
 		$tn = array_filter($tn);
		$sql = "update res_file set carIds=',".implode(",",$c).",',carNames=',".implode(",",$cn).",',typeIds=',".implode(",",$t).",',typeNames=',".implode(",",$tn).",' where id in(".$INCOME['id'].")";
		$DB->db_query($sql);
		//echo $sql;
		echo "<script>parent.saveTypeResult(1);</script>";
	}
	function ajaxRemoveFile()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		$did = $INCOME['did'];
		$id = $INCOME['id'];
		if($did && $id)
		{
			$did = explode(",",$did);
			$id = explode(",",$id);
			
			foreach($id as $i)
			{
					$r = $DB->db_query_first("select * from res_file where id=".$i);
					$dbDid = array();
					if($r['dirIds'])
					{
						$dbDid = explode(",",$r['dirIds']);
					}
					$newdbdid = array();
					foreach($dbDid as $v)
					{
						if($v)
						{
							$newdbdid[] = $v;
						}
					}
					$dbDid = $newdbdid;
					$newUpdate = array();
					foreach($dbDid as $didr)
					{
						$isHave = false;
						foreach($did as $d)
						{
                           if($didr==$d)
						   {
							   $isHave = true;
						   }
						}
						if(!$isHave)
						{
							$newUpdate[]= $didr;
						}
					}
					$DB->db_query("update res_file set  dirIds=',".implode(",",$newUpdate).",' where id=".$i);
			}
		}
		$data = array("st"=>"ok","msg"=>"成功");
 		echo $GJson->encode($data);
	}
	function ajaxDirFile()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		$did = $INCOME['did'];
		$id = $INCOME['id'];
		if($did && $id)
		{
            $arrDid = explode(",",$did);
			$did = $did.",";
			$id = explode(",",$id);
				foreach($id as $i)
				{
					$r = $DB->db_query_first("select * from res_file where id=".$i);
					$dbDid = array();
					if($r['dirIds'])
					{
						$dbDid = explode(",",$r['dirIds']);
					}
					$newdbdid = array();
					foreach($dbDid as $v)
					{
						if($v)
						{
							$newdbdid[] = $v;
						}
					}
					$dbDid = $newdbdid;
					foreach($arrDid as $d)
					{
						if(!in_array($d,$dbDid))
						{
							$dbDid[] = $d;
						}
					}
					$DB->db_query("update res_file set  dirIds=',".implode(",",$dbDid).",' where id=".$i);
				}
			 
		}
		$data = array("st"=>"ok","msg"=>"成功");
 		echo $GJson->encode($data);
	}
	function ajaxDel()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		$id = $INCOME['id'];
		if($id)
		{
			$DB->db_query("update res_file set isPost=4 where id in(".$id.")");
		}
		$data = array("st"=>"ok","msg"=>"删除成功");
 		echo $GJson->encode($data);
	}
	function ajaxDelDir()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		if($INCOME['id'])
		{
			$r = $DB->db_query_first("select * from res_file where dirIds like ',%".$INCOME['id'].",%' ");
			if($r)
			{
				$data = array("st"=>"err","msg"=>"删除失败 该目录下有文件");
			}
			else
			{
				$DB->db_query("delete from res_dir where id=".$INCOME['id']);
				$data = array("st"=>"ok","msg"=>"删除成功");
			}
			echo $GJson->encode($data);
		}
	}
	function ajaxSaveDir()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;

		if($INCOME['id'])
		{
			$r = $DB->db_query_first("select * from res_dir where name='".$INCOME['name']."' and id!=".$INCOME['id']);
			if($r)
			{
				echo "exist";
				exit;
			}
			$f['edtTime'] =$gCurTime;
			$f['name'] = $INCOME['name'];
			$DB->db_form_update("res_dir",$f,"id=".$INCOME['id']);
		}
		else
		{
			$r = $DB->db_query_first("select * from res_dir where name='".$INCOME['name']."'");
			if($r)
			{
				echo "exist";
				exit;
			}
			$f['name'] = $INCOME['name'];
			$f['uid']= $_SESSION['adminUser']['id'];
			$f['uname']= $_SESSION['adminUser']['name'];
		 	$f['addTime'] =$gCurTime;
			$DB->db_form_insert("res_dir",$f);
		}
		echo "ok";
	}
	function ajaxLstDir()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson;
		$sql = "SELECT * FROM res_dir where uid=".$_SESSION['adminUser']['id']." order by id desc";
		$DB->db_query($sql);
		$games = array();
		//$games[] = array("id"=>0,"name"=>"全部目录");
		while($r=$DB->db_fetch_row())
		{
			$games[] = array("id"=>$r['id'],"name"=>$r['name']);
		}
		echo $GJson->encode($games);
	}
	function saveInfo()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson,$gCurTime;
		if($INCOME['id'] || $INCOME['pdid'])
		{
			if($INCOME['id']=="0" && $INCOME['pdid']>0)
			{
				$DB->db_query("select id from res_file where dirIds like '%,".$INCOME['pdid'].",%' and isPost=0");
				if($DB->db_fetch_num()>0)
				{
					$ids = array();
					while($r=$DB->db_fetch_row())
					{
						$ids[] = $r['id'];
					}
					$INCOME['id'] = implode(",",$ids);
				}
			}
		$f = $DB->getDBFields($INCOME);
		$f['edtTime'] = $gCurTime;
		if($INCOME['optype']=="post")
		{
			$f['isPost'] = 1;
		}
		else
		{
			$f['isPost'] = 3;
		}
		if($INCOME['isPost']==-1)
		{
			$f['isPost'] = 2;
		}
		$DB->db_form_update("res_file",$f,"id in(".$INCOME['id'].")",false);
		if($INCOME['src']=="ajax")
		{
			$data = array("st"=>"ok","msg"=>"成功");
 			echo $GJson->encode($data);
		}
		else
		{
		 	echo '<script>parent.saveResult(1,"'.$INCOME['optype'].'");</script>';
	     }
		}
		
		
	}
	function ajaxType()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$GJson;
		$sql = "SELECT * FROM type where parId=".$INCOME['id']." and isHide=0";
		$DB->db_query($sql);
		$games = array();
		while($r=$DB->db_fetch_row())
		{
			$games[] = array("id"=>$r['id'],"name"=>$r['name']);
		}
		echo $GJson->encode($games);
	}
	function detail()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$_SESSION,$gCurTime;
		$rf = $DB->db_query_first("select * from res_file where id=".$INCOME['id']);
		$rf['path'] = str_replace("s.","sb.",$rf['path']);
		$gSmarty->assign("f",$rf);
		$gSmarty->display("upload/".__FUNCTION__.".tpl");
	}
    function saveFile()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$_SESSION,$gCurTime,$gFileType,$GJson;
		 
		//$INCOME['path'] = str_replace("\\","/",urldecode($INCOME['path']));
		//echo urldecode($INCOME['path']);
		$fileInfo = pathinfo($INCOME['path']);
		//var_dump($fileInfo);
		$f['fid'] =  uniqid("file_");
		$newPath = $fileInfo['dirname']."/".$f['fid'].".".strtolower($fileInfo['extension']);
		rename($INCOME['path'],$newPath);
		$f['name'] = $INCOME['name'];
		$f['ext'] =  strtolower($fileInfo['extension']);
		if($f['ext']=="jpeg")
		{
			$f['ext'] = str_replace("jpeg","jpg",$f['ext']);
		}
		$f['path']= $newPath;
		$extType = $gFileType[$f['ext']];
		if($extType['id']==39)
		{
			include "lib/ResizeImage.php";
			//echo $newPath;
			$minPath = str_replace(".","s.",$f['path']);
		    //$gWeb->resizeImage($newPath,$minPath,200,135);
			new ResizeImage($newPath, 200,135, '0',$minPath);
			//$gWeb->resizeImage($f['path'],$minPath,692,550);
			$f['path']= $minPath;
			$minPath = str_replace(".","b.",$f['path']);
			//$gWeb->resizeImage($newPath,$minPath,692,550);
			new ResizeImage($newPath, 692,550, '0',$minPath);
			$minPath = str_replace(".","m.",$f['path']);
			//$gWeb->resizeImage($newPath,$minPath,300,300);
			new ResizeImage($newPath, 300,300, '0',$minPath);
		}
		if($extType)
		{
			$f['fileTypeId'] = $extType['id'];
			$f['fileTypeName'] = $extType['n'];
		}
		else
		{
			$f['fileTypeId'] = "0";
			$f['fileTypeName'] = "";
		}
		$f['dirIds']= ",".$INCOME['dirId'].",";
		$f['dirNames']= ",".$INCOME['dirName'].",";
		$f['uid']= $_SESSION['adminUser']['id'];
		$f['uname']= $_SESSION['adminUser']['name'];
		$f['size'] = filesize($newPath);
		if(empty($f['size']))
		{
			$f['size'] = 0;
		}
		$f['addTime'] =$gCurTime;
		//$DB->db_form_insert("res_file",$f);
		$data = array("st"=>"ok","msg"=>"成功","fid"=>$INCOME['fid'],"path"=>$minPath,"data"=>base64_encode(serialize($f)));
 		echo $GJson->encode($data);
	}
	function index()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$_SESSION;
 
		$gSmarty->display(basename(__FILE__,'.php')."/".__FUNCTION__.".tpl");
	}
	function saveFileImg()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$_SESSION,$gCurTime,$gFileType,$GJson;
		 
		//$INCOME['path'] = str_replace("\\","/",urldecode($INCOME['path']));
		//echo urldecode($INCOME['path']);
		$editId = $INCOME['edit'];
		if($editId)
		{
			$dbfileInfo = $DB->db_query_first("select * from res_file where id=".$editId);
		}
		else
		{
			$data = array("st"=>"err","msg"=>"缺少id");
 			echo $GJson->encode($data);
			exit;
		}
		$fileInfo = pathinfo($INCOME['path']);
		//var_dump($fileInfo);
		$f['fid'] =  $dbfileInfo['fid'];
		$newPath = $fileInfo['dirname']."/".$f['fid'].".".strtolower($fileInfo['extension']);
		rename($INCOME['path'],$newPath);
		$f['name'] = $INCOME['name'];
		$f['ext'] =  strtolower($fileInfo['extension']);
		if($f['ext']=="jpeg")
		{
			$f['ext'] = str_replace("jpeg","jpg",$f['ext']);
		}
		$f['path']= $newPath;
		$extType = $gFileType[$f['ext']];
		if($extType['id']==39)
		{
			include "lib/ResizeImage.php";
			//echo $newPath;
			$minPath = str_replace(".","s.",$f['path']);
		    //$gWeb->resizeImage($newPath,$minPath,200,135);
			new ResizeImage($newPath, 200,135, '0',$minPath);
			//$gWeb->resizeImage($f['path'],$minPath,692,550);
			$f['path']= $minPath;
			$minPath = str_replace(".","b.",$f['path']);
			$maxPic = $minPath;
			//$gWeb->resizeImage($newPath,$minPath,692,550);
			new ResizeImage($newPath, 692,550, '0',$minPath);
			$minPath = str_replace(".","m.",$f['path']);
			//$gWeb->resizeImage($newPath,$minPath,300,300);
			new ResizeImage($newPath, 300,300, '0',$minPath);
		}
		$data = array("st"=>"ok","msg"=>"成功","path"=>$maxPic);
 		echo $GJson->encode($data);
	}
		function getLstFile()
	{
		global $gSmarty,$gAct,$gOp,$INCOME,$DB,$gWeb,$_SESSION,$GJson,$gFileType,$gPageName;
		$timeField = "postTime";
 
		//if($INCOME['f'])
		//{
			//$conArr[] ="ext = '".$INCOME['did']."'";
		//}
		//$conArr[] ="isGroupTop > 0";
		$conArr[] ="isDel = 0";
		if($INCOME['k'])
		{
			$conArr[] ="(mark like '%".$INCOME['k']."%' or name like '%".$INCOME['k']."%' or keywords like '%".$INCOME['k']."%')";
		}
 
			if($INCOME['src']=="edit")
			{
				if($INCOME['st'])
				{
					if($INCOME['st']==5)
					{
						
						$DB->db_query("select fid from res_app_file where touid=".$_SESSION['adminUser']['id']." and isChecked=0");
						
						//$conArr[] ="isPost in (3,4,5)";
						$allId = array();
						while($r=$DB->db_fetch_row())
						{
							$allId[] = $r['fid'];
						}
						$conArr[] ="isPost = ".$INCOME['st']." and id in(".implode(",",$allId).")";
						//var_dump($conArr);
					}
					else
					{
						$conArr[] ="isPost = ".$INCOME['st'];
						if($_SESSION['adminUser']['roleId']!=1 && $_SESSION['adminUser']['roleId']!=4)
						{
							$conArr[] ="uid = ".$_SESSION['adminUser']['id'];
						}
						
					}
				}
				else
				{
					$conArr[] ="isPost = 0";
						if($_SESSION['adminUser']['roleId']!=1 && $_SESSION['adminUser']['roleId']!=4)
						{
							$conArr[] ="uid = ".$_SESSION['adminUser']['id'];
						}
				}
				$timeField = "addTime";
			}
			else {
				$conArr[] ="isPost = 1";
			}
		 
		if($conArr)
		{
			$con ="where ". implode(" and ",$conArr);
		}
        
 		$sql = "SELECT count(*) as num FROM res_file_subject $con";
 		//echo $sql;
		$iPerPage = 12;
		if($INCOME['src']=="edit")
		{
		    $iPerPage = 21;
		}
		if($INCOME['src']=="m")
		{
		    $iPerPage = 9;
		}
		if($INCOME['ps'])
		{
			$iPerPage = $INCOME['ps'];
		}
		if($iPerPage>50)
		{
			$iPerPage = 1;
		}
		$r = $DB->db_query_first($sql);
		$allNum = $r['num'];
		$totalPage = ceil($allNum/$iPerPage);
		$ajax = $INCOME['ajax']?$INCOME['ajax']:"getPage";
		$queryUrl = $gPageName."?act=".$gAct."&op=".$gOp."&b=".$INCOME['b']."&c=".$INCOME['c']."&t=".$INCOME['t']."&s=".$INCOME['s']."&y=".$INCOME['y']."&k=".$_GET['k']."&did=".$INCOME['did']."&ajax=".$ajax."&st=".$INCOME['st']."&ps=".$INCOME['ps']."&src=".$INCOME['src'];
		$pageClass = new MyPage(array (
		'total' => $allNum,
		'perpage' => $iPerPage,
		'url' => $queryUrl
		));
		$pageClass->open_Ajax($ajax);
		$page = empty ($INCOME['page']) ? 1 : $INCOME['page'];
		$iStartNo = ($page -1) * $iPerPage;
		$sql = "SELECT id,name,path,ext,mark,fileTypeName FROM res_file_subject $con order by $timeField desc LIMIT {$iStartNo}, {$iPerPage}";
		//echo $sql;
		$DB->db_query($sql);
		$data = null;
		$idx = 0+($page-1)*$iPerPage;
		while($r = $DB->db_fetch_row())
		{
		    $idx++;
			//$r['disId'] = $idx;
			$fileType = $gFileType[$r['ext']];
			if($fileType['n']=="图片")
			{
				$r['pic'] = $r['path'];
			}
			else
			{
				$r['pic'] = $fileType['p'];
				if(empty($r['pic']))
				{
					$r['pic'] ="images/ico/doc.png";
				}
			}
			if($r['mark'])
			{
				$r['name'] = $r['mark']."<br/>".$r['name'];
			}
		    $data[] = $r;
			unset($fileType);	
		}
		$pageNav = $pageClass->show();
		if($INCOME['src']=="m")
		{
			$pageNav = $pageClass->simpleShow();
			$pageNav = str_replace("上一页","<img src='images/p.png'/>",$pageNav);
			$pageNav = str_replace("下一页","<img src='images/n.png'/>",$pageNav);
			$pageNav = str_replace("span","div",$pageNav);
		}
		echo $GJson->encode(array("st"=>"ok","tp"=>$totalPage,"u"=> $queryUrl,"data"=>array("data"=>$data,"total"=>$allNum,"pageNav"=>$pageNav)));
		 
	}
	
}
?>